﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using ThuVien;

namespace TranTekBE.Kho
{
    public partial class Kiem_Ke_Hang_Hoa : PageRequireLogin
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Page.Form.DefaultButton = btnSubmit.UniqueID;
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string MaCode = txtCode.Text;
            string DivHtml;
            string sql = null;
            string MaPOS = null;
            string MaVach = null;
            //
            // Split the string on line breaks.
            // ... The return value from Split is a string array.
            //
            // Check POS / Ma Vach
            int check_POS_MaVach = 0;
            if (MaCode.Contains(";"))
            {
                // POS
                string[] items_POS = Regex.Split(MaCode, ";");
                MaPOS = items_POS[0];

                check_POS_MaVach = check_POS_MaVach + 1;
            }
            else
            {
                // Ma Vach
                // check_POS_MaVach = 0;
                MaVach = MaCode;
            }
            //
            if (check_POS_MaVach == 0)
            {
                sql = "MaVach";
            }
            else
            {
                sql = "MaPOS";
            }
            DataSet ds = FunctionsUtils.Database.ExecuteQuery(sql);
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[1].Rows.Count > 0)
            {
                if (ViewState["CountItems"] != null)
                    ViewState["CountItems"] = Convert.ToInt32(ViewState["CountItems"]) + 1;
                else
                    ViewState["CountItems"] = 1;
                DivHtml = "";

            }
        }
    }
}